package com.newer.controller.sys;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.newer.pojo.sys.Resource;
import com.newer.service.sys.iter.ResourceService;
import com.newer.utils.sys.BootstrapDataTable;
import com.newer.utils.sys.MsgUtil;

@RequestMapping("resource")
@Controller
public class ResourceController {

	/**
	 * 自动注入
	 */
	@Autowired
	private ResourceService resourceService;

	/**
	 * 显示资源列表
	 * 
	 * @param bootstrapDataTable
	 * @param conditions
	 * @return
	 */
	@RequestMapping("tableView")
	public @ResponseBody BootstrapDataTable tableView(BootstrapDataTable bootstrapDataTable) {
		return resourceService.tableView(bootstrapDataTable);
	}

	/**
	 * 级联删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("delete/{id}")
	public @ResponseBody MsgUtil deleteResource(@PathVariable("id") Integer id) {
		List<Integer> list = new ArrayList<Integer>();
		list.add(id);
		// 执行删除
		boolean result = resourceService.deleteResource(list);
		if (result == true) {
			return MsgUtil.result(result, "删除成功");
		} else {
			return MsgUtil.result(result, "删除失败");
		}
	}

	/**
	 * 资源树
	 * 
	 * @return
	 */
	@RequestMapping("tree")
	public @ResponseBody List<Resource> resourceTree() {
		//return resourceService.resourceTree();
		return null;
	}

	/**
	 * 添加
	 * 
	 * @param resource
	 *            资源
	 * @return
	 */
	@RequestMapping("add")
	public @ResponseBody MsgUtil addResource(Resource resource) {
		
		return MsgUtil.result(true, "");
	}

}
